#pragma once
#ifndef DEF_H
#define DEF_H

#include <QString>
///////////////////////////////////////////////////////////////
// LABLE CAPTION
///////////////////////////////////////////////////////////////

#define DEFAULT_URL "http://dev.worldcastinc.com"

#define LABEL_USER			"Username"
#define LABEL_PASSWORD		"Password"
#define LABEL_URL			"URL Base"
#define LABEL_SOURCE		"Source"
#define LABEL_MUTE			"Mute"
#define LABEL_PAUSE			"Pause"
#define LABEL_PLAYBACK		"Playback"

#define LABEL_SLOT_ID			"<b>Slot ID:</b> "
#define LABEL_HASH				"<b>Hash:</b> "
#define LABEL_START				"<b>Start:</b> "
#define LABEL_END				"<b>End:</b> "
#define LABEL_CUSTOMER			"<b>Cust. ID:</b> "
#define LABEL_PROVIDER			"<b>Prov. ID:</b> "
#define LABEL_MODE				"<b>Mode:</b> "
#define LABEL_AVAILABLE			"<b>Available:</b> "
#define LABEL_IC_SERVER			"<b>Server:</b> "
#define LABEL_IC_PORT			"<b>Port:</b> "
#define LABEL_IC_USER			"<b>User:</b> "
#define LABEL_IC_PASS			"<b>Pass:</b> "
#define LABEL_IC_MOUNT			"<b>Mount:</b> "
#define LABEL_CHANNEL			"Channels: "
#define LABEL_CHANNEL_MONO		"Mono"
#define LABEL_CHANNEL_STEREO	"Stereo"
#define LABEL_SAMPLE			"Frequency: "
#define LABEL_FRAME_RATE		"FPS: "
#define LABEL_QUALITY			"Quality: "
#define LABEL_BITRATE			"Bit rate (kbps): "
#define LABEL_KEYFRAME_COUNT	"Key frame shift: "
#define LABEL_DROP_FRAME		"Drop frames"
#define LABEL_FAST_MODE			"Fast mode"
#define LABEL_AUTO_BITRATE		"Auto BitRate"
#define LABEL_VORBIS			"Audio Settings"
#define LABEL_THEORA			"Video Settings"
#define LABEL_NOT_AVAIL			"N/A"
#define LABEL_CURRENT_SESSION	"Current Session"
#define LABEL_NEXT_SESSION		"Next Session"
#define LABEL_BEFORE_SESSION_START		"Before Session Start"
#define LABEL_BEFORE_SESSION_END		"Before Session End"
#define LABEL_STATUS_READY		"Ready"
#define LABEL_STATUS_CONNECTED	"Connected"
#define LABEL_STATUS_PAUSED		"Paused"
#define LABEL_NO_PROVIDER		"No Provider"
#define LABEL_RESOLUTION		"Resolution: "
#define LABEL_ORG_RESOLUTION	"Original"

#define TITLE_SECTION_PREVIEW	"Preview"
#define TITLE_SECTION_INFO		"Slot Information"
#define TITLE_SECTION_STREAM	"Stream Information"
#define TITLE_SECTION_CONTROL	"Control"
#define TITLE_SECTION_AUDIO		"Audio"
#define TITLE_SECTION_VIDEO		"Video"
#define TITLE_SECTION_SESSION	"Session"

#define TITLE_FORM_LOGIN		"Worldcast OMPS Login"
#define TITLE_FORM_MAIN			"WCI Video/Audio Streamer"
#define TITLE_FORM_SETTINGS		"Settings"
#define TITLE_FORM_MSGBOX		"Worldcast OMPS"
#define LABEL_TIME_ZERO			"0:00"

#define SETTINGS_FILENAME		"conf.dat"
#define SETTINGS_VIDEO			"Video"
#define SETTINGS_AUDIO			"Audio"
#define SETTINGS_QUALITY		"quality"
#define SETTINGS_FPS			"fps"
#define SETTINGS_CHANNEL		"channel"
#define SETTINGS_RATE			"rate"
#define SETTINGS_KFRAME_SHIFT	"kframe"
#define SETTINGS_DROPFRAME		"drop"
#define SETTINGS_FASTMODE		"fmode"
#define SETTINGS_AUTOBITRATE	"autobr"
#define SETTINGS_VIDEO_SIZE		"vsize"
#define SETTINGS_TIME_FORMAT	"yyyy-MM-dd hh:mm:ss"

#define TAG_CODE_BEGIN			"<code>"
#define TAG_CODE_END			"</code>"
#define TAG_TOKEN_BEGIN			"<token>"
#define TAG_TOKEN_END			"</token>"
#define TAG_SLOT_BEGIN			"<slot>"
#define TAG_SLOT_END			"</slot>"

#define MAX_VIDEO_WIDTH				(2048)
#define MAX_VIDEO_HEIGHT			(1024)

///////////////////////////////////////////////////////////////
// BUTTON CAPTION
///////////////////////////////////////////////////////////////

#define BUTTON_LOGIN		"Login"
#define BUTTON_CANCEL		"Cancel"
#define BUTTON_START		"Start"
#define BUTTON_STOP			"Stop"
#define BUTTON_PAUSE		"Pause"
#define BUTTON_RESUME		"Resume"
#define BUTTON_REFRESH		"Refresh"
#define BUTTON_SETTING		"Setting"
#define BUTTON_SAVE			"Save"

//////////////////////////////////////////////////////////////
// MESSAGE
//////////////////////////////////////////////////////////////

#define MSG_LOGIN_EMPTY_URL		"Based URL cannot be blank."
#define MSG_LOGIN_EMPTY			"User or password is empty. Please check and try again."
#define MAG_LOGIN_WRONG			"User and password were not recognized. Please check and try again."
#define MSG_LOGIN_INVALID_USR	"Invalid username or password."
#define MSG_LOGIN_CANNOT_CONN	"Cannot connect to server."
#define MSG_LOGIN_SUCCESS		"Login Successful."
#define MSG_HTTP_ERROR			"403"

//////////////////////////////////////////////////////////////
// PARAMS
//////////////////////////////////////////////////////////////

#define AUTH "auth"
#define GET_SLOTS "getslots"
#define INIT_STREAM "initStream"
#define FREE_STREAM "freeStream"
#define MAX_LEN  1024

#define STR_CPY(dst, src) {if(dst)free(dst);dst=(char*)malloc(strlen(src)+1);strcpy(dst,src);}
#define STR_DEL(str) {if(str)free(str);str=0;}

#include <ogg/ogg.h>

typedef struct _IceCastSlot
{
	// slot info
	int id;
	char *hash;
	char *timeStart;
	char *timeEnd;
	char *custLocation;
	char *custTimeZone;
	int customerid;
	char *customer_name;
	int providerid;
	char *provider_name;
	int testmode;
	int available;

	// stream info
	char *host;
	int port;
	char *user;
	char *pass;
	char *mount;
	// link next
	_IceCastSlot *next;
} IceCastSlot;

#define CLONE_SLOT_INFO(x, y)	{					\
	y = (IceCastSlot*)malloc(sizeof(IceCastSlot));	\
	memset(y, 0, sizeof(IceCastSlot));				\
	y->id = x->id;									\
	STR_CPY(y->hash, x->hash);						\
	STR_CPY(y->timeStart, x->timeStart);			\
	STR_CPY(y->timeEnd, x->timeEnd);				\
	STR_CPY(y->custLocation, x->custLocation);		\
	STR_CPY(y->custTimeZone, x->custTimeZone);		\
	y->customerid = x->customerid;					\
	STR_CPY(y->customer_name, x->customer_name);	\
	y->providerid = x->providerid;					\
	STR_CPY(y->provider_name, x->provider_name);	\
	y->testmode = x->testmode;						\
	y->available = x->available;					\
}

#define DEL_SLOT_INFO(x) {		\
	STR_DEL(x->hash);			\
	STR_DEL(x->timeStart);		\
	STR_DEL(x->timeEnd);		\
	STR_DEL(x->custLocation);	\
	STR_DEL(x->custTimeZone);	\
	STR_DEL(x->customer_name);	\
	STR_DEL(x->provider_name);	\
	free(x);					\
}

typedef struct _IceCastServerInfo
{
	char *ip;
	int port;
	char *mountPoint;
	char *username;
	char *pwd;
} IceCastServerInfo;

typedef struct _PacketList
{
	ogg_packet *packet;
	_PacketList *next;
} PacketList;

typedef float TYPE_SAMPLE_IN;	// Data type used in output buffer. S16_LE works on SB/ALSA.
typedef float TYPE_SAMPLE_OUT;	// Data type used in output buffer. S16_LE works on SB/ALSA.

PacketList *clonePacket(PacketList *packet);
PacketList *createPacket(ogg_packet *packet);
void freePackets(PacketList *packets);

#endif // DEF_H
